package com.tywj.panda.customer.common.view.base

import android.os.Bundle
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.LifecycleOwner

import com.tywj.panda.customer.common.view.BaseDialog
import com.tywj.lib.businessweak.view.IBaseView

/**
 * @desc 基类Dialog
 *  @author : June Yang
 * @date 2018/5/9
 */
abstract class MyBaseDialog : BaseDialog(), IBaseView {

    private lateinit var baseView: IBaseView

    override fun initVariable(savedInstanceState: Bundle?) {
        super.initVariable(savedInstanceState)

        baseView = BaseViewImpl(childFragmentManager, this)

        // TODO: 这个代码提取到基础库中
        savedInstanceState?.let {
            if (!getRecoveryAfterCrash()) {
                dismissDialog()
            }
        }
    }

    override fun shortToast(msg: CharSequence) {
        baseView.shortToast(msg)
    }

    override fun shortToast(id: Int) {
        baseView.shortToast(id)
    }

    override fun longToast(msg: CharSequence) {
        baseView.longToast(msg)
    }

    override fun longToast(id: Int) {
        baseView.longToast(id)
    }

    override fun showLoadingDialog(msg: String) {
        baseView.showLoadingDialog(msg)
    }

    override fun showLoadingDialog(id: Int) {
        baseView.showLoadingDialog(id)
    }

    override fun dismissLoadingDialog() {
        baseView.dismissLoadingDialog()
    }

    override fun getLifecycleOwner(): LifecycleOwner {
        return baseView.getLifecycleOwner()
    }

    override fun getFragmentManagerInstance(): FragmentManager {
        return baseView.getFragmentManagerInstance()
    }

    /**
     * App崩溃恢复后，是否恢复崩溃前正在显示的弹窗
     */
    protected fun getRecoveryAfterCrash(): Boolean = false
}